package com.enterprise.support.servlet;

import nl.justobjects.pushlet.Version;
import nl.justobjects.pushlet.core.*;
import nl.justobjects.pushlet.servlet.Pushlet;
import nl.justobjects.pushlet.util.Log;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 11-5-29
 * Time: 上午8:32
 * To change this template use File | Settings | File Templates.
 */
public class PushletServlet extends Pushlet {
    public void init() throws ServletException {
        try {
            // Load configuration (from classpath or WEB-INF root path)
            String webInfPath = getServletContext().getRealPath("/") + "/WEB-INF/classes/config/pushlet";
            Config.load(webInfPath);

            Log.init();

            // Start
            Log.info("init() Pushlet Webapp - version=" + Version.SOFTWARE_VERSION + " built=" + Version.BUILD_DATE);

            // Start session manager
            SessionManager.getInstance().start();

            // Start event Dispatcher
            Dispatcher.getInstance().start();


            if (Config.getBoolProperty(Config.SOURCES_ACTIVATE)) {
                EventSourceManager.start(webInfPath);
            } else {
                Log.info("Not starting local event sources");
            }
        } catch (Throwable t) {
            throw new ServletException("Failed to initialize Pushlet framework " + t, t);
        }
    }

}